package com.course.controller;

import com.course.entity.ResultBody;
import com.course.service.CourseDisplayService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

@RestController
@RequestMapping("/CourseManagement")
@CrossOrigin(origins="*")
public class CourseDisplayController {
//学生端课程列表
    @Autowired
    private CourseDisplayService courseManService;
    @RequestMapping("/courseList")
    public ResultBody courseList(){
        return  courseManService.courseList();
    }
//学生端课程详细信息
    @RequestMapping("/coursemessage")
    public ResultBody course(@RequestBody Map<String ,Object> map) {
        if (map.get("courseid") == null) {
            return new ResultBody(404, "参数错误", false);
        } else
            return courseManService.courseMessage(map);
    }
//老师端课程列表
    @RequestMapping("/teachmessage")
    public ResultBody teachmessage(@RequestBody Map<String ,Object> map) {
        if(map.get("usernumber") == null) {
            return new ResultBody(404,"参数错误",false);
        }
        Object objecti = map.get("usernumber");
        Integer usernumber;
        if(objecti instanceof Integer) {
            usernumber = (Integer)objecti;
        }
        else if(objecti instanceof String) {
            usernumber = Integer.parseInt((String)objecti);
        }
        else
            return new ResultBody(400,"未知参数",false);
        return courseManService.teachmessage(usernumber);
    }
}
